Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 4 - Geometric Operations / Using Geometric Operations


Simplifying Shapes

In addition to unnecessary geometric points, there are other aspects of shape geometries that complicate the definition and drawing of a shape. Some examples are:

The sample function in Listing 4-4 creates a polygon shape with a single contour that crosses over itself.

Listing 4-4 Creating a polygon shape with a crossed contour

void CreateHourglassPolygon(void)
{
   gxShape aPolygonShape;

   static long hourglassGeometry[] = {1, /* number of contours */
                                      4, /* number of points */
                                      ff(50), ff(50),
                                      ff(150), ff(50),
                                      ff(50), ff(150),
                                      ff(150), ff(150)};

   aPolygonShape = GXNewPolygons((gxPolygons *) 
                                 hourglassGeometry);
   GXSetShapeFill(aPolygonShape, gxClosedFrameFill);
   
   GXDrawShape(aPolygonShape);
   GXDisposeShape(aPolygonShape);
}
The resulting polygon shape is shown in Figure 4-24.

Figure 4-24 A polygon shape with a crossed contour

QuickDraw GX provides the GXSimplifyShape function so you can eliminate unnecessary contour breaks, crossed contours, and overlapping contours. This function takes one parameter: a reference to the shape you want to simplify.

As an example, adding the function call

GXSimplifyShape(aPolygonShape);
to the sample function in Listing 4-4 creates the polygon shown in Figure 4-25.

Figure 4-25 A polygon shape with no crossed contours

Notice that although this polygon shape is simplified, it contains more geometric points and more contours than the original polygon. However, the crossed contour is eliminated.

As another example, the sample function in Listing 4-5 creates a path shape with two concentric contours: an outer contour and an inner contour, both of which have a clockwise contour direction.

Listing 4-5 Creating a path shape with two clockwise contours

void CreateConcentricPaths(void)
{
   gxShape aPathShape;

   static long twoCircleGeometry[] = {2, /* # of contours */
                                      4, /* # of points */
                                      0xF0000000, /* 1111 ... */
                                      ff(50), ff(50),   /* off */
                                      ff(150), ff(50),  /* off */
                                      ff(150), ff(150), /* off */
                                      ff(50), ff(150),  /* off */
                                      4, /* # of points */
                                      0xF0000000, /* 1111 ... */
                                      ff(65), ff(65),   /* off */
                                      ff(135), ff(65),  /* off */
                                      ff(135), ff(135), /* off */
                                      ff(65), ff(135)}; /* off */


   aPathShape = GXNewPaths((gxPaths *) twoCircleGeometry);
   GXSetShapeFill(aPathShape, gxEvenOddFill);
   
   GXDrawShape(aPathShape);
   GXDisposeShape(aPathShape);
}
Figure 4-26 shows the result of this sample function.

Figure 4-26 A path shape with two concentric clockwise contours and even-odd shape fill

Applying the GXSimplifyShape function to the path shape in Figure 4-26 reverses the contour direction of the inner contour, so that it is no longer an overlapping contour with the same contour direction. The result is shown in Figure 4-27.

Figure 4-27 A path shape with two concentric contours with opposite contour direction

However, imagine that the path shape defined in Listing 4-5 originally had a winding fill, as shown in Figure 4-28.

Figure 4-28 A path shape with two concentric clockwise contours and winding shape fill

In this case, the GXSimplifyShape function removes the inner contour entirely, as it is not necessary to describe the shape as drawn. The result is shown in Figure 4-29.

Figure 4-29 A path shape simplified to a single clockwise contour

The GXSimplifyShape function can change the shape type of a shape, as well the geometry of shape, if the shape can be expressed by a simpler shape type. For example, a polygon shape is converted to a rectangle shape or a line shape, if possible. Similarly, a path shape is converted to a polygon shape if it has no off-curve control points.

For a discussion of shape fills and contour direction, see Chapter 2, "Geometric Shapes," in this book.

For more information about the GXSimplifyShape function, see page 4-76.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help